//
//  ViewController.swift
//  BWHUDKit
//
//  Created by 朱旭宏 on 03/08/2022.
//  Copyright (c) 2022 朱旭宏. All rights reserved.
//

import UIKit
import BWHUDKit
import BWToolKit

class ViewController: UIViewController {
    lazy var customView = UIView(frame: .init(origin: .zero, size: .init(width: 200, height: 80)))

    @IBAction func showPopup(_ sender: UIControl) {
        HUD.popup(sender: sender, icon: .init(named: "more_collected"), text: "short text", action: .init(title: "CLOSE", icon: nil, handler: {

        }))
    }
    
    @IBAction func showHUD(_ sender: UISegmentedControl) {
//        HUD.tips(.success, text: "LongTextLongTextLongTextLongTextLongTextLongTextLongTextLongTextLongTextLongTextLongTextLongText")
        
//        HUD.toast(icon: .success, text: "LongTextLongTextLongTextLongTextLongTextLongTextLongTextLongTextLongTextLongTextLongTextLongText")
        
//        let iv = UIImageView(image: .init(named: "more_collected"))
//        HUD.show(.square(.init(customView: iv, duration: 1)))
        
        
//        HUD.show(.toast(.init(text: "TopTopTopTopTopTopTopTopTopTopTopTopTopTopTopTopTopTopTopTopTopTopTopTopTopTopTopTopTopTopTopTopTopTopTop", position: .top)))
//        HUD.show(.toast(.init(text: "Bottom", position: .bottom)))
//        HUD.show(.toast(.init(text: "Center")))
        
//        customView.backgroundColor = .green
//        HUD.popup(sender: sender, customView: customView)
        
//        HUD.toast(icon: .init(named: "more_collected"), text: "This is a long toast")
        
//        let label = UILabel(font: .system20)
//        label.text = "Hello Toast Customized!"
//        HUD.toast(customView: label)
        
//        HUD.tips(.custom(.init(named: "more_collected")), text: "操作成功!!!")
        
//        HUD.toast("Toast1")
//        HUD.tips(.success, text: "Square")
//        HUD.tips(.error, text: "Square")
        
//        HUD.loading(.ring, duration: 3)
//        HUD.loading(.indicator)
        
        
//        HUD.snackbar(icon: .error, text: "Error")
        
        /*
        let button = UIButton(type: .system)
        button.tintColor = .red
        button.setTitle("Hello Snackbar Customized!", for: .normal)
        button.bw_tapped { _ in
            HUD.dismiss()
            HUD.toast("hello Snackbar")
        }
        HUD.snackbar(customView: button)
        
        
        HUD.snackbar(icon: .success, text: "SnackbarSnackbarSnackbarSnackbarSnackbarSnackbarSnackbarSnackbar", action: .init(title: "Action", icon: nil, handler: {
            HUD.toast("Success")
        }), poistion: .top)
        HUD.snackbar(icon: .custom(.init(named: "more_collected")), text: "Customized", poistion: .bottom)
        HUD.snackbar(icon: .error, text: "Error")
        HUD.snackbar(icon: .warning, text: "Warning")*/
        
//        HUD.popup(sender: sender, icon: nil, text: "Hello popupHello popupHello popupHello popupHello popupHello popupHello popupHello popupHello popupHello popupHello popupHello popupHello popupHello popup")
        
//        HUD.loading(duration: 10)
//
        progress = 0
        timer = GCD.dispatchTimer(delay: 0, interval: 0.2, repeats: true, autoResume: true, in: .main, handler: { [weak self] in
            guard let self = self else { return }
            if self.progress >= 1 {
                self.timer?.cancel()
                HUD.dismiss(first: .progress)
                return
            }
            HUD.progress(
                .water,
                value: self.progress,
                text: String(format: "进度: %d%%", Int(self.progress*100)),
                canceller:
            {
                self.timer?.cancel()
                HUD.dismiss(all: .progress)
            },
                completion:
            {
                HUD.tips(.success)
            })
            HUD.dismiss(first: .loading)
            self.progress += 0.01
            print(self.progress)
        })
    }
    var progress: CGFloat = 0
    var timer: GCDTimer?

}

